#!/bin/bash


LONGNAME="Traffic analyzer"
NAME="traff_meter"
DAEMON="$TWMFOLDER/modules/if_meter/$NAME.sh"

set -e

case $1 in
start)
	PID=`ps ax | grep $NAME.sh | grep -v grep | gawk '{print $1}'`
	if [ "$PID" = "" ]; then
		echo -n "Starting $LONGNAME: ";
		$DAEMON 2>&1 >/dev/null &
		echo "............................done";
		PID=`ps ax | grep $NAME.sh | grep -v grep | gawk '{print \$1}'`
		echo $PID > /var/run/$NAME.pid
	else
		echo "WARNING! Daemon is started already."
	fi
	;;
stop)
	PID=`ps ax | grep $NAME.sh | grep -v grep | gawk '{print $1}'`
	if [ "$PID" = "" ]; then
		echo "Daemon $LONGNAME is not running.";
	else
		echo -n "Stopping $LONGNAME: "
		kill $PID
		if [ -e /var/run/$NAME.pid ]; then
			rm /var/run/$NAME.pid
		fi
		echo "............................done";
	fi
	;;
restart)
        shift
        $0 stop
        $0 start "$@"
        ;;
*)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart}" >&2
	exit 1
	;;
esac

exit 0

# EOF
